package org.komarichin.beans.dao;

import java.io.Serializable;
import java.util.Collection;

/**
 * Generic dao
 * User: Mykhaylo Komarichyn
 * Date: 17.03.2010
 * Time: 10:53:29
 */
public interface IGenericDAO<T, PK> extends Serializable {
    /**
     * @param entity saving entity
     * @return saved entity
     */
    T save(T entity);

    /**
     * @param entity entity for update
     * @return entity's primary key
     */
    PK saveOrUpdate(T entity);

    /**
     * @param id entity's id
     */
    void remove(PK id);

    /**
     * @param id entity id
     * @return entity object or null
     */
    T findById(PK id);

    /**
     * @return all entities in bd
     */
    Collection<T> getAll();

    /**
     * @param start     start result
     * @param limit     max returned result in query
     * @param fieldName field by sorting
     * @param order     sort order, true as asc, false as desc
     * @return result as article object by criteria
     */
    Collection<T> getEntityByParams(int start, int limit, String fieldName, boolean order);


    /**
     * @return count entities
     */
    int getCountEntities();

    /**
     * @return new instance of entity object, but not persistence object
     */
    T newInstance();
}
